package com.biyao.service.model.product.imp;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import java.util.HashMap;
import java.util.Map;

import com.biyao.schedulingdao.product.TProductionPlanMapper;
import com.biyao.schedulingentity.product.TProductionPlanEntity;
import com.biyao.service.model.product.ProductionPlanMessage;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.ArrayList;
/**
 * 
 *
 * @author code generator
 * @date 2019-09-16 09:44:18
 */
@Service
public class TProductionPlanService extends ServiceImpl<TProductionPlanMapper, TProductionPlanEntity> implements ProductionPlanMessage {

    public Page list(int pageNum, int pageSize){

        EntityWrapper<TProductionPlanEntity> tProductionPlanentityWrapper=new EntityWrapper<>();
        Page page=selectPage(new Page(pageNum,pageSize),tProductionPlanentityWrapper);
        page.setRecords(formatRecords(page.getRecords()));
        return page;
    }

    List formatRecords(List<TProductionPlanEntity> list){
        List resList=new ArrayList();
        for(TProductionPlanEntity tProductionPlanEntity:list){
            Map map=formatEntity(tProductionPlanEntity);
            resList.add(map);
        }
        return resList;
    }

    Map formatEntity(TProductionPlanEntity tProductionPlanEntity){
        Map map=new HashMap(16);
        //生产计划表头
        if(tProductionPlanEntity.getId()!=null){
           map.put("id",tProductionPlanEntity.getId());
        }
        //描述
        if(tProductionPlanEntity.getDescription()!=null){
           map.put("description",tProductionPlanEntity.getDescription());
        }
        //是否有效
        if(tProductionPlanEntity.getValid()!=null){
           map.put("valid",tProductionPlanEntity.getValid());
        }
        //备注
        if(tProductionPlanEntity.getRemark()!=null){
           map.put("remark",tProductionPlanEntity.getRemark());
        }
        if(tProductionPlanEntity.getCode()!=null){
            map.put("code",tProductionPlanEntity.getCode());
        }
        if(tProductionPlanEntity.getName()!=null){
            map.put("name",tProductionPlanEntity.getName());
        }
        //
        if(tProductionPlanEntity.getCreateTime()!=null){
           map.put("createTime",tProductionPlanEntity.getCreateTime());
        }
        //
        if(tProductionPlanEntity.getUpdateTime()!=null){
           map.put("updateTime",tProductionPlanEntity.getUpdateTime());
        }
        //
        if(tProductionPlanEntity.getCreateBy()!=null){
           map.put("createBy",tProductionPlanEntity.getCreateBy());
        }
        //
        if(tProductionPlanEntity.getUpdateBy()!=null){
           map.put("updateBy",tProductionPlanEntity.getUpdateBy());
        }
        return map;
    }

    @Override
    public List<Map> selectProduction(int pageNum, int pageSize) {
        EntityWrapper<TProductionPlanEntity> tProductionPlanentityWrapper=new EntityWrapper<>();
        Page page=selectPage(new Page(pageNum,pageSize),tProductionPlanentityWrapper);
        return formatRecords(page.getRecords());
    }

    @Override
    public Integer addProduction(TProductionPlanEntity tProductionPlanEntity) {
          insert(tProductionPlanEntity);
          return tProductionPlanEntity.getId();
    }

    @Override
    public void updateProduction(TProductionPlanEntity tProductionPlanEntity) {
        updateById(tProductionPlanEntity);
    }

    @Override
    public TProductionPlanEntity selectProductionPalnById(Integer id) {
        return selectById(id);
    }

    @Override
    public void deleteProductionPlanById(Integer id) {
        deleteById(id);
    }
}

